﻿#region LicenseInfo
/*
 * WoW Automation
 * Copyright 2008, 2009
 * Michael Sutton
 * 
 * This file is part of Wow Automation.
 * 
 * Wow Automation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Wow Automation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Wow Automation.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Drawing;


namespace Automation
{
    class BootStrapper
    {
     //   public BGinfo playerStatus = new BGinfo();
       // public BGinfo playerStatusOld = new BGinfo();
        private readonly KeyPushUtils kpu = new KeyPushUtils();




      
        #region Events
        /// <summary>
        /// Event triggers whenever your x,y position on the map changes
        /// </summary>
        public event BGInfoEventHandler PositionChanged;
        protected virtual void OnPositionChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = PositionChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

/// <summary>
/// Event triggers whenever the zone information changes
/// </summary>
        public event BGInfoEventHandler ZoneChanged;
        protected virtual void OnZoneChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = ZoneChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }
        
        /// <summary>
        /// Event triggers whenever the subzone changes
        /// </summary>
        public event BGInfoEventHandler SubZoneChanged;
        protected virtual void OnSubZoneChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = SubZoneChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        /// <summary>
        /// Event triggers when your char joins a raid or leaves a raid
        /// </summary>
        public event BGInfoEventHandler InRaidChanged;
        protected virtual void OnInRaidChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = InRaidChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        /// <summary>
        /// Event triggers when you move indoors
        /// </summary>
        public event BGInfoEventHandler isOutDoorsChanged;
        protected virtual void OnisOutDoorsChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = isOutDoorsChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        /// <summary>
        /// Event triggers when you have died.
        /// </summary>
        public event BGInfoEventHandler isDeadChanged;
        protected virtual void OnisDeadChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = isDeadChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        /// <summary>
        /// Event triggers when you join a BG queue
        /// </summary>
        public event BGInfoEventHandler inQueueChanged;
        protected virtual void OninQueueChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = inQueueChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        /// <summary>
        /// Event triggers when you change what direction your facting in game.
        /// </summary>
        public event BGInfoEventHandler coordsFacingChanged;
        protected virtual void OncoordsFacingChanged(EventBgInfoArgs e)
        {
            BGInfoEventHandler eh = coordsFacingChanged;
            if (eh != null)
            {
                eh(this, e);
            }
        }

        #endregion

        /// <summary>
        /// This does a comparison of values between old and new and fires the appropriate event if there is a change.
        /// </summary>
        private void AnalyzeDifferences()
        {
            if (CommonVariables.PlayerStatus.X == -1) return;
            if (!CommonVariables.PlayerStatus.ValidScan) return;
            
            if (CommonVariables.PlayerStatus.AB != CommonVariables.PlayerStatusOld.AB ||
                CommonVariables.PlayerStatus.AV != CommonVariables.PlayerStatusOld.AV ||
                CommonVariables.PlayerStatus.Darnassus != CommonVariables.PlayerStatusOld.Darnassus ||
                CommonVariables.PlayerStatus.EOS != CommonVariables.PlayerStatusOld.EOS ||
                CommonVariables.PlayerStatus.IronForge != CommonVariables.PlayerStatusOld.IronForge ||
                CommonVariables.PlayerStatus.Shatrath != CommonVariables.PlayerStatusOld.Shatrath ||
                CommonVariables.PlayerStatus.Stormwind != CommonVariables.PlayerStatusOld.Stormwind ||
                CommonVariables.PlayerStatus.WSG != CommonVariables.PlayerStatusOld.WSG ||
                CommonVariables.PlayerStatus.SilverMoon != CommonVariables.PlayerStatusOld.SilverMoon
                )
            {
                OnZoneChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }

            if (CommonVariables.PlayerStatus.abGraveYard1 != CommonVariables.PlayerStatusOld.abGraveYard1 ||
                  CommonVariables.PlayerStatus.abGraveYard1 != CommonVariables.PlayerStatusOld.abGraveYard1 ||
                  CommonVariables.PlayerStatus.abGraveYard2 != CommonVariables.PlayerStatusOld.abGraveYard2 ||
                  CommonVariables.PlayerStatus.abGraveYard3 != CommonVariables.PlayerStatusOld.abGraveYard3 ||
                  CommonVariables.PlayerStatus.abGraveYard4 != CommonVariables.PlayerStatusOld.abGraveYard4 ||
                  CommonVariables.PlayerStatus.abGraveYard5 != CommonVariables.PlayerStatusOld.abGraveYard5 ||
                  CommonVariables.PlayerStatus.abGraveYard6 != CommonVariables.PlayerStatusOld.abGraveYard6 ||
                  CommonVariables.PlayerStatus.abGraveYard7 != CommonVariables.PlayerStatusOld.abGraveYard7 ||

                  CommonVariables.PlayerStatus.avGraveYard1 != CommonVariables.PlayerStatusOld.avGraveYard1 ||
                  CommonVariables.PlayerStatus.avGraveYard2 != CommonVariables.PlayerStatusOld.avGraveYard2 ||
                  CommonVariables.PlayerStatus.avGraveYard3 != CommonVariables.PlayerStatusOld.avGraveYard3 ||
                  CommonVariables.PlayerStatus.avGraveYard4 != CommonVariables.PlayerStatusOld.avGraveYard4 ||
                  CommonVariables.PlayerStatus.avGraveYard5 != CommonVariables.PlayerStatusOld.avGraveYard5 ||
                  CommonVariables.PlayerStatus.avGraveYard6 != CommonVariables.PlayerStatusOld.avGraveYard6 ||
                  CommonVariables.PlayerStatus.avGraveYard7 != CommonVariables.PlayerStatusOld.avGraveYard7 ||
                  CommonVariables.PlayerStatus.avGraveYard8 != CommonVariables.PlayerStatusOld.avGraveYard8 ||

                  CommonVariables.PlayerStatus.eosGraveYard1 != CommonVariables.PlayerStatusOld.eosGraveYard1 ||
                  CommonVariables.PlayerStatus.eosGraveYard2 != CommonVariables.PlayerStatusOld.eosGraveYard2 ||
                  CommonVariables.PlayerStatus.eosGraveYard3 != CommonVariables.PlayerStatusOld.eosGraveYard3 ||
                  CommonVariables.PlayerStatus.eosGraveYard4 != CommonVariables.PlayerStatusOld.eosGraveYard4 ||
                  CommonVariables.PlayerStatus.eosGraveYard5 != CommonVariables.PlayerStatusOld.eosGraveYard5 ||

                  CommonVariables.PlayerStatus.wsgGraveYard != CommonVariables.PlayerStatusOld.wsgGraveYard
                )
            {
                OnSubZoneChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }

            if (CommonVariables.PlayerStatus.Dead != CommonVariables.PlayerStatusOld.Dead)
            {
                OnisDeadChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            if (CommonVariables.PlayerStatus.Facing != CommonVariables.PlayerStatusOld.Facing)
            {
                OncoordsFacingChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            if (CommonVariables.PlayerStatus.inQueue != CommonVariables.PlayerStatusOld.inQueue)
            {
                OninQueueChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            if (CommonVariables.PlayerStatus.InRaid != CommonVariables.PlayerStatusOld.InRaid)
            {
                OnInRaidChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            if (CommonVariables.PlayerStatus.Inside != CommonVariables.PlayerStatusOld.Inside)
            {
                OnisOutDoorsChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            if (
                CommonVariables.PlayerStatus.X != CommonVariables.PlayerStatusOld.X ||
                CommonVariables.PlayerStatus.Y != CommonVariables.PlayerStatusOld.Y
                )
            {
                OnPositionChanged(new EventBgInfoArgs(CommonVariables.PlayerStatus));
            }
            CommonVariables.PlayerStatusOld = CommonVariables.PlayerStatus;
        }


        /// <summary>
        /// This will grab a screenshot, and fire off events when somthing has changed from the last value.
        /// </summary>
        /// <returns></returns>
        public Bitmap processPass()
        {
            Bitmap bmp =  kpu.ScrapeScreen();
            AnalyzeDifferences();
            return bmp;
        }
    }
}
